package com.yang.system.common.framework;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;

import static com.yang.system.common.framework.ChangingStatus.*;

// lastUPdatedAt 和 lastUpdatedBy 的 setter 以及所有属性的 getter
@Getter
@NoArgsConstructor
public abstract class AuditableEntity {
    protected ChangingStatus changingStatus = NEW;
    @Setter
    protected LocalDateTime createdAt;
    @Setter
    protected Long createdBy;
    @Setter
    protected LocalDateTime lastUpdatedAt;
    @Setter
    protected Long lastUpdatedBy;

    public AuditableEntity(LocalDateTime createdAt, Long createdBy) {
        this.createdAt = createdAt;
        this.createdBy = createdBy;
    }

    public void toUpdate() {
        this.changingStatus = UPDATED;
    }

    public void toDelete() {
        this.changingStatus = DELETED;
    }

    public void toUnChang() {
        this.changingStatus = UNCHANGED;
    }

}
